package com.kdgc.power.base.controller;
import com.kdgc.power.base.entity.BaseRegion;
import com.kdgc.power.base.service.BaseRegionService;
import com.kdgc.power.fw.bean.JsonMsg;
import com.kdgc.power.fw.bean.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("BaseRegion")
public class BaseRegionController {
    @Autowired
    private BaseRegionService baseRegionService;

    @RequestMapping("page")
    public Object getPage(HttpServletRequest request, int page, int rows) {
        return baseRegionService.getPage("baseRegion.select", null, page, rows);
    }

    @RequestMapping("findById")
    public Map<String, Object> findById(Integer id) {
        return baseRegionService.getMapEntity(id);
    }
    @RequestMapping("findByParentId")
    public Object findByParentId(String parentId) {
        return baseRegionService.findByParentId(parentId);
    }

    @RequestMapping("save")
    public JsonMsg save(BaseRegion entity) {
        boolean success = baseRegionService.saveOrUpdate(entity);
        return new JsonMsg(success);
    }

    @RequestMapping("deleteById")
    public JsonMsg deleteById(Integer id) {
        int rows = baseRegionService.removeById(id);
        return new JsonMsg(rows == 1);
    }
    @RequestMapping("getTree")
    public List<TreeNode> getTree() {
        return baseRegionService.getTree();
    }
}